// pages/order/refund/refund.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        reason: ['大小/尺寸与商品描述不符', '日期/年份不符', '质量问题', '少件（含缺少配件）', '卖家发错货', '其他'],
        index: 0,
        uploadImg: [],
        maxImg: 9
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    bindPickerChange: function(e) {
        this.setData({
            index: e.detail.value
        })
    },

    uploadImg: function() {
        if (this.data.maxImg < 1) {
            wx.showToast({
                title: "最多上传9张图片",
                duration: 1000
            })
            return
        }
        const that = this
        let uploadImg = this.data.uploadImg
        let maxImg = this.data.maxImg
        wx.chooseImage({
            count: maxImg, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function(res) {
                wx.showToast({
                    icon: "loading",
                    title: "正在上传图片",
                    duration: 1000
                })
                const tempFilePaths = res.tempFilePaths
                tempFilePaths.forEach(function(e) {
                    maxImg--
                    uploadImg.push(e)
                    that.setData({
                        uploadImg: uploadImg
                    })
                    that.setData({
                        maxImg: maxImg
                    })
                    wx.uploadFile({
                        url: 'https://example.weixin.qq.com/upload', //仅为示例，非真实的接口地址
                        filePath: e,
                        name: 'file',
                        success(res) {
                            const data = res.data
                        }
                    })
                })
            }
        })
    },

    deleteImg: function(e) {
        let uploadImg = this.data.uploadImg
        let maxImg = this.data.maxImg
        maxImg++
        uploadImg.splice(e.currentTarget.dataset.index, 1)
        this.setData({
            uploadImg: uploadImg
        })
        this.setData({
            maxImg: maxImg
        })
    },

    refundSubmit: function() {
        wx.navigateTo({
            url: '/pages/order/refundResult/refundResult'
        })
    }
})